home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / russell / russell.lha / examples / gauss.r < prev    next >
Text File  |  1989-12-29  |  2KB  |  41 lines

  1. let
  2.     GaussianInteger ==
  3.                 record { Real,Imaginary: Short }
  4.                 with GI{
  5.                     i ==  func[] val GI {
  6.                               GI$Mk[0,1]
  7.                           };
  8.                     toGI == func[x: val Short] val GI {
  9.                                 GI$Mk[x,0]
  10.                             };
  11.                     + == func[x,y: val GI] {
  12.                             GI$Mk[
  13.                                 Real[x] + Real[y],
  14.                                 Imaginary[x] + Imaginary[y]
  15.                             ]
  16.                          };
  17.                     - == func[x,y: val GI] {
  18.                             GI$Mk[
  19.                                 Real[x] - Real[y],
  20.                                 Imaginary[x] - Imaginary[y]
  21.                             ]
  22.                          };
  23.                     * == func[x,y: val GI] {
  24.                             GI$Mk[
  25.                               Real[x] * Real[y] - Imaginary[x] * Imaginary[y],
  26.                               Real[x] * Imaginary[y] + Imaginary[x] * Real[y]
  27.                             ]
  28.                         };
  29.                     put == func[x: val GI] val Void {
  30.                                    put[Real[x]];
  31.                                    put["+"];
  32.                                    put[Imaginary[x]];
  33.                                    put["i"];
  34.                                }
  35.                 }
  36.                 hide {Mk}
  37. in use GaussianInteger in
  38.     put[ toGI[5] + toGI[2] * i]; put ["\n"]
  39. ni ni
  40.  
  41.